#include "BreakPointState.h"

BreakPointState::BreakPointState()
:status(END)
{

}
BreakPointState::~BreakPointState(){
}

bool BreakPointState::isEnd() const {
    return status == END;
}
bool BreakPointState::isInited() const {
    return status == INITED;
}
bool BreakPointState::isConnected() const{
    return status == CONNECTED;
}
bool BreakPointState::isLogined() const {
    return status == LOGINED;
}
bool BreakPointState::isDisconnected() const {
    return status == DISCONNECTED;

}

// State Switch Table   
//      [cur][next] == 1 => switch Ok;  
//      [cur][next] == 0 -> Failed
//            END -> INITED -> CONNECTED -> LOGINED -> DISCONNECTED
//    
//END          0       1           0           0           0
//
//INITED       1       0           1           0           0
//
//CONNECTED    1       0           0           1           1
//
//LOGINED      1       0           0           0           1
//
//DISCONNECTED 1       0           0           0           0
int BreakPointState::toEnd() {
    if(!isEnd()){
        status = END;;
        return 0;
    }
    return -1;
}
int BreakPointState::toInited()  {
    if(isEnd()){ 
        status = INITED;
        return 0;
    }
    return -1;
}
int BreakPointState::toConnected() {
    if(isInited()){
        status = CONNECTED;
        return 0;
    }
    return -1;
}
int BreakPointState::toLogined() {
    if(isConnected()){
        status = LOGINED;
        return 0;
    }
    return -1;
}
int BreakPointState::toDisconnected() {
    if(isLogined() || isConnected()){
        status = DISCONNECTED;
        return 0;
    }
    return -1;
}

std::ostream &  BreakPointState::log(std::ostream & out){
    out << "\tstatus :"  << status << " [0-end,1-inited,2-connected,3-logined,4-disconnected]" << std::endl;
    return out;
}

